//
//  QLMAddBaoxiuTopCell.m
//  Xiaomakuaixiu
//
//  Created by 龚碧容 on 2017/10/14.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "QLMAddBaoxiuTopCell.h"

@implementation QLMAddBaoxiuTopCell

- (void)_creatMainUI{
    
    self.trodecriptionTextView.layer.masksToBounds=YES;
    self.trodecriptionTextView.layer.cornerRadius=5;
    self.trodecriptionTextView.backgroundColor=[UIColor clearColor];
    
    self.trodecriptionTextView.placeholderColor=[UIColor lightGrayColor];
    self.trodecriptionTextView.placeholder=@"请详细描述故障情况（1-50字）";
    
    for (int i=0; i<2; i++) {
        UIView *line1=[[UIView alloc] initWithFrame:CGRectMake(17, 49.5+50*i, kScreen_width-17, 0.5)];
        line1.backgroundColor=[UIColor lightGrayColor];
        [self addSubview:line1];
    }
//    UIView *line2=[[UIView alloc] initWithFrame:CGRectMake(17, 199.5+50, kScreen_width-17, 0.5)];
//    line2.backgroundColor=[UIColor lightGrayColor];
//    [self addSubview:line2];
    
    NSArray *titlArr=[NSArray arrayWithObjects:@"设备*",@"服务类型*",@"故障选择*",@"故障说明*",nil];
    for (int i=0; i<titlArr.count; i++) {
        
        NSString *telStr=[NSString stringWithFormat:@"%@",titlArr[i]];
        NSMutableAttributedString *aString=[[NSMutableAttributedString alloc] initWithString:telStr];
        [aString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(telStr.length-1, 1)];
        if (i<3) {
            UILabel *aTipLabel=[[UILabel alloc] initWithFrame:CGRectMake(20, 10+50*i, 70, 30)];
            aTipLabel.font=[UIFont systemFontOfSize:15];
            aTipLabel.textColor=[UIColor darkGrayColor];
            aTipLabel.attributedText=aString;
            aTipLabel.backgroundColor=[UIColor whiteColor];
            aTipLabel.textAlignment=NSTextAlignmentLeft;
            [self addSubview:aTipLabel];
            
            if (i==2) {
                _troubleLabel=aTipLabel;
            }
            
        }else{
            self.desciptTip1Label.font=[UIFont systemFontOfSize:15];
            self.desciptTip1Label.attributedText=aString;
        }
        
    }
    
    self.baoxiuBtn=[self _creatButton:CGRectMake(90, 60, 50, 30) title:@"维修" image:nil];
    self.baoxiuBtn.tag=878;
    [self addSubview:self.baoxiuBtn];
    self.baoyangBtn=[self _creatButton:CGRectMake(150, 60, 50, 30) title:@"保养" image:nil];
    self.baoyangBtn.tag=879;
    [self addSubview:self.baoyangBtn];
    
    self.firstBtn=[self _creatButton:CGRectMake(90, 60+50, 50, 30) title:@"发动机" image:nil];
    self.firstBtn.tag=880;
    [self addSubview:self.firstBtn];
    self.secondBtn=[self _creatButton:CGRectMake(150, 60+50, 50, 30) title:@"电气" image:nil];
    self.secondBtn.tag=881;
    [self addSubview:self.secondBtn];
    self.thirdBtn=[self _creatButton:CGRectMake(210, 60+50, 50, 30) title:@"液压" image:nil];
    self.thirdBtn.tag=882;
    [self addSubview:self.thirdBtn];
    self.fourthBtn=[self _creatButton:CGRectMake(270, 60+50, 50, 30) title:@"其它" image:nil];
    self.fourthBtn.tag=883;
    [self addSubview:self.fourthBtn];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

- (IBAction)addDeviceAction:(UIButton *)sender {
    [_delegate addDeviceAction];
}

- (void)troubleTypeAction:(UIButton *)sender {
    [_delegate troubleTypeAction:sender.tag];
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    
    static NSString *identifiew=@"QLMAddBaoxiuTopCellId";
    QLMAddBaoxiuTopCell *cell=[tableView dequeueReusableCellWithIdentifier:identifiew];
    if (cell==nil) {
        cell=[[[NSBundle mainBundle] loadNibNamed:@"QLMAddBaoxiuTopCell" owner:nil options:nil] firstObject];
    }
    return cell;
}

- (UIButton *)_creatButton:(CGRect)aFrame title:(NSString *)aTitle image:(NSString *)imageName{
    UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
    newButton.frame = aFrame;
    newButton.titleLabel.font=[UIFont systemFontOfSize:15];
    [newButton setTitle:aTitle forState:UIControlStateNormal];
    [newButton setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
    newButton.backgroundColor = UIColorFromRGB(0xf6f6f6);
    [newButton addTarget:self action:@selector(troubleTypeAction:) forControlEvents:UIControlEventTouchUpInside];
    return newButton;
}

@end
